import os

from django.db import models
from typing_extensions import deprecated

from common.snowflake import Snowflake


class Device(models.Model):
    """
    设备相关模型
    """
    id = models.BigIntegerField(primary_key=True, default=Snowflake.generate, verbose_name="主键")
    reseller_id = models.BigIntegerField(blank=True, null=True, verbose_name="分销商id")
    reseller_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="分销商id")
    shop_id = models.BigIntegerField(blank=True, null=True, verbose_name="店铺id")
    shop_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="店铺名称")
    account_id = models.BigIntegerField(blank=True, null=True, verbose_name="客户id")
    account_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="客户名称")
    serial_code = models.CharField(max_length=255, blank=True, null=True, verbose_name="序列号")
    machine_code = models.CharField(max_length=255, blank=True, null=True, verbose_name="机器码")
    app_version = models.CharField(max_length=50, blank=True, null=True, verbose_name="火眼客户端版本")
    sdk_version = models.CharField(max_length=50, blank=True, null=True, verbose_name="火眼SDK版本")
    platform_type = models.IntegerField(blank=True, null=True, verbose_name="平台类型")
    platform_version = models.CharField(max_length=255, blank=True, null=True, verbose_name="平台版本号")
    # TODO 可能会去掉
    detect_rate = models.FloatField(blank=True, null=True, verbose_name="识别率")
    detect_count = models.IntegerField(blank=True, null=True, verbose_name="识别次数")
    # TODO 这里为何是二进制文件
    cert_encrypt_key = models.BinaryField(blank=True, null=True, verbose_name="证书加密密钥")
    cert_data = models.CharField(max_length=255, blank=True, null=True, verbose_name="证书")

    # 证书相关
    cert_create_time = models.DateTimeField(blank=True, null=True, verbose_name="证书创建时间")
    cert_renewal_time = models.DateTimeField(blank=True, null=True, verbose_name="证书续期时间")
    cert_expire_time = models.DateTimeField(blank=True, null=True, verbose_name="证书过期时间")
    # 序列相关时间
    serial_active_time = models.DateTimeField(blank=True, null=True, verbose_name="序列号首次激活时间")
    serial_expire_time = models.DateTimeField(blank=True, null=True, verbose_name="序列号过期时间")
    # ts文件相关
    ts_file_url = models.CharField(max_length=255, null=True, blank=True, verbose_name="ts文件url")
    ts_file_status = models.IntegerField(blank=True, null=True, verbose_name="ts文件状态")
    ts_file_hash_value = models.CharField(max_length=255, blank=True, null=True, verbose_name="ts哈希值")

    class Meta:
        db_table = 'fe_device_test'
        managed = False
        verbose_name = verbose_name_plural = "设备模型"